<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2017/6/13
 * Time: 下午11:14
 */
class ModRanking
{
    public static function serverData($params){
        $table = 'tblGameCoinUsedRanking';
        $where  = ' WHERE RecDate = :date AND Platform=:platform AND Period = :period AND GameSrc=:game AND CoinType = :coinType ';
        $args   = array(
            ':date'     => $params['date'],
            ':period'   => "Daily",
            ':game'     => $params['g'],
            ':platform' => $params['os'],
            ':coinType' => $params['coinType'],
        );

        if(!empty($params['server']) && $params['server'] !== 'ALL'){
            $where .= 'AND SID=:server';
            $args[':server'] = $params['server'];
        }else{
            $where .= 'AND SID = "ALL"';
        }

        $sql = "SELECT * FROM {$table} {$where} ORDER BY GetNumber DESC";

        $dbLink = new PubDbLink('dbSelf', PubDatabase::getMgmtDbName($params['p'], $params['g']));

        return $dbLink->query($sql, $args);
    }
}